/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//Need to clarify several issues
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import type.AtpCheckStatus;
import type.BackorderStatus;


/**
 *
 * @author Andy
 */
@Entity(name = "Backorder")
public class BackorderEntity extends DataObjectEntity implements Serializable {

    @OneToOne
    private SalesOrderEntity salesOrder;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date requiredLeadTime;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date confirmedLeadTime;
    @OneToMany (cascade={CascadeType.ALL}, mappedBy="backorder")
    private Collection<ProductQuantityPriceEntity> productQuantityPriceList = new ArrayList<ProductQuantityPriceEntity>();
    private BackorderStatus status;
    private boolean isMrpUpdated = false; // to tell if the recommended mrp updates are done or not
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date earliestMrpFulfillmentDate;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date earliestSopFulfillmentDate;
    
    private HashMap<Long,Double> reservedCapacity = new HashMap<Long,Double>();
    
    @OneToMany(mappedBy="backOrder1")
    Collection<MrpToQuantityEntity> failedAtpMrps = new ArrayList<MrpToQuantityEntity>();
    
    @OneToMany(mappedBy="backOrder2") 
    Collection<MrpToQuantityEntity> updatedAtpMrps = new ArrayList<MrpToQuantityEntity>(); // mrps whose planned orders are updated when backOrder is apporved
    
    @OneToMany(mappedBy="backOrder3")
    Collection<MrpToQuantityEntity> reservedAtpMrps = new ArrayList<MrpToQuantityEntity>();//record reservation of mrp quantity 
    
    private AtpCheckStatus mrpCheckStatus; // pass or fail for mrpAtp check
    
    public BackorderEntity() {
        super();
        status = BackorderStatus.ProductionPending;
    }
    
    public boolean getIsMrpUpdated(){
        return isMrpUpdated;
    }
    
    public void setReservedAtpMrps(ArrayList<MrpToQuantityEntity> reservedAtpMrps){
        this.reservedAtpMrps = reservedAtpMrps;
    }
    
    public Collection<MrpToQuantityEntity> getReservedAtpMrps(){
        return reservedAtpMrps;
    }
    
    public void setIsMrpUpdated(boolean isMrpUpdated){
        this.isMrpUpdated = isMrpUpdated;
    }
    
    public Date getEarliestMrpFulfillmentDate(){
        return earliestMrpFulfillmentDate;
    }
    
    public void setEarliestMrpFulfillmentDate(Date date){
        earliestMrpFulfillmentDate = date;
    }
    
     public Date getEarliestSopFulfillmentDate(){
        return earliestSopFulfillmentDate;
    }
    
    public void setEarliestSopFulfillmentDate(Date date){
        earliestSopFulfillmentDate = date;
    }

    public BackorderStatus getStatus() {
        return status;
    }
    
    public Collection<MrpToQuantityEntity> getFailedAtpMrps(){
        return failedAtpMrps;
    }
    
    public void setFailedAtpMrps(Collection<MrpToQuantityEntity> failedAtpMrps){
        this.failedAtpMrps = failedAtpMrps;
    }
    
    public Collection<MrpToQuantityEntity> getUpdatedAtpMrps(){
        return updatedAtpMrps;
    }
    
    public void setUpdatedAtpMrps(Collection<MrpToQuantityEntity> updatedAtpMrps){
        this.updatedAtpMrps = updatedAtpMrps;
    }
    
    public void setMrpCheckStatus(AtpCheckStatus atpCheckStatus){
        mrpCheckStatus = atpCheckStatus;
    }
    
    public AtpCheckStatus getMrpCheckStatus(){
        return mrpCheckStatus;
    }

    public void setStatus(BackorderStatus status) {
        this.status = status;
    }

    public Date getConfirmedLeadTime() {
        return confirmedLeadTime;
    }

    public void setConfirmedLeadTime(Date confirmedLeadTime) {
        this.confirmedLeadTime = confirmedLeadTime;
    }

    public Date getRequiredLeadTime() {
        return requiredLeadTime;
    }

    public void setRequiredLeadTime(Date requiredLeadTime) {
        this.requiredLeadTime = requiredLeadTime;
    }

    public Collection<ProductQuantityPriceEntity> getProductQuantityPriceList() {
        return productQuantityPriceList;
    }

    public void setProductQuantityPriceList(Collection<ProductQuantityPriceEntity> productQuantityPriceList) {
        this.productQuantityPriceList = productQuantityPriceList;
    }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    @Override
    public String childToString() {
        return "BackorderEntity{" + "salesOrder=" + salesOrder + ", requiredLeadTime=" + requiredLeadTime + ", confirmedLeadTime=" + confirmedLeadTime + ", ProductQuantityPriceList=" + productQuantityPriceList + '}';   
}

    public HashMap<Long,Double> getReservedCapacity() {
        return reservedCapacity;
    }

    public void setReservedCapacity(HashMap<Long,Double> reservedCapacity) {
        this.reservedCapacity = reservedCapacity;
    }
}

class PlannedReservedList {

    private HashMap weeklyRequirement;

    public PlannedReservedList() {
        weeklyRequirement = new HashMap();
    }

    public HashMap getMonthlyRequirement() {
        return weeklyRequirement;
    }

    public void setMonthlyRequirement(HashMap monthlyRequirement) {
        this.weeklyRequirement = monthlyRequirement;
    }
}
